//
//  MenuLayer.m
//  xGame
//
//  Created by Max on 11-8-14.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MenuLayer.h"
#import "GameLayer.h"


@implementation MenuLayer

+(CCScene *)scene
{
    CCScene *scene = [CCScene node];
    
    MenuLayer *layer =[MenuLayer node];
    
    [scene addChild:layer];
    
    return scene;
}

-(id)init
{
    if((self==[super init]))
    {
        [CCMenuItemFont setFontSize:25];
		
		CCMenuItem *newGame = [CCMenuItemFont itemFromString:@"新游戏" target:self selector:@selector(newGame:)];
		CCMenuItem *loadGame = [CCMenuItemFont itemFromString:@"高分榜" target:self selector:nil];
		CCMenuItem *GameSttings = [CCMenuItemFont itemFromString:@"设置" target:self selector:@selector(OnSettings:)];
		CCMenuItem *helpGame = [CCMenuItemFont itemFromString:@"帮助" target:self selector:nil];
		CCMenuItem *quitGame = [CCMenuItemFont itemFromString:@"退出" target:self selector:@selector(onQuit:)];
		
		CCMenu *mn = [CCMenu menuWithItems:newGame, loadGame, GameSttings, helpGame, quitGame, nil];
		[mn alignItemsVertically];
		
		[self addChild:mn z:1 tag:500];
    }
    
    return self;
}

- (void) newGame:(id) sender
{
//	CCScene *sc = [CCScene node];
//	[sc addChild:[GameLayer node]];
//	
//	[[CCDirector sharedDirector] replaceScene: [CCSlideInRTransition transitionWithDuration:1.2f scene:sc]];
    
    CCTransitionScene *ts =[CCTransitionScene transitionWithDuration:0.5f scene:[GameLayer scene]];
	[[CCDirector sharedDirector] replaceScene:ts];
	
}

- (void) OnSettings:(id) sender
{
//	CCScene *sc = [CCScene node];
//	[sc addChild:[SettingsLayer node]];
//	
//	[[CCDirector sharedDirector] replaceScene: [CCShrinkGrowTransition transitionWithDuration:1.2f scene:sc]];
	
}

-(void) onQuit: (id) sender
{
    /*
     [[CCDirector sharedDirector] end];
     
     // HA HA... no more terminate on sdk v3.0
     // http://developer.apple.com/iphone/library/qa/qa2008/qa1561.html
     if( [[UIApplication sharedApplication] respondsToSelector:@selector(terminate)] )
     [[UIApplication sharedApplication] performSelector:@selector(terminate)];
     else
     CCLOG(@"YOU CAN'T TERMINATE YOUR APPLICATION PROGRAMATICALLY in SDK 3.0+");
     */
}


-(void)dealloc
{
    [super dealloc];
}

@end
